<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>策略模式与状态模式：深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(to bottom, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 0 8px 8px 0;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .pattern-bg {
            background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%239C92AC' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
    </style>
</head>
<body class="pattern-bg">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 tracking-tight">
                策略模式 vs 状态模式
            </h1>
            <p class="text-xl md:text-2xl font-light opacity-90 max-w-3xl mx-auto">
                深入理解两种行为设计模式的本质差异与应用场景
            </p>
            <div class="mt-10 flex justify-center space-x-8">
                <div class="text-center">
                    <i class="fas fa-chess text-4xl mb-2"></i>
                    <p class="text-sm">策略选择</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-exchange-alt text-4xl mb-2"></i>
                    <p class="text-sm">状态转换</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-code text-4xl mb-2"></i>
                    <p class="text-sm">行为封装</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto bg-white rounded-2xl shadow-xl p-10 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">策</span>略模式（Strategy Pattern）和状态模式（State Pattern）都是行为设计模式，但它们的目的和应用场景存在显著的差异。理解这两种模式的区别，对于构建灵活、可维护的软件系统至关重要。
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-8 px-6">
        <div class="max-w-6xl mx-auto grid md:grid-cols-2 gap-8">
            
            <!-- Strategy Pattern -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover animate-fadeInUp">
                <div class="flex items-center mb-6">
                    <i class="fas fa-chess-knight text-4xl feature-icon mr-4"></i>
                    <h2 class="text-3xl font-bold text-gray-800">策略模式</h2>
                </div>
                
                <p class="text-gray-600 mb-6 leading-relaxed">
                    策略模式允许在运行时选择算法的行为或策略，通过将算法封装成独立的类，客户端可以选择所需的策略实现。
                </p>
                
                <div class="mb-8">
                    <h3 class="text-xl font-semibold mb-4 section-title text-gray-800">
                        <i class="fas fa-star text-sm mr-2"></i>主要特点
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">算法的封装：</strong>
                                <span class="text-gray-600">各种算法被封装在独立的策略类中，符合开闭原则。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">动态选择：</strong>
                                <span class="text-gray-600">客户端可以在运行时选择适当的策略，实现灵活的行为变更。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">相互独立：</strong>
                                <span class="text-gray-600">不同策略之间相互独立，便于扩展和维护。</span>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 section-title text-gray-800">
                        <i class="fas fa-lightbulb text-sm mr-2"></i>适用场景
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">多种算法选择：</strong>
                                <span class="text-gray-600">当系统有多个可互换的算法或行为时，例如排序算法、支付方式等。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">消除条件语句：</strong>
                                <span class="text-gray-600">当算法的选择逻辑复杂，使用策略模式可以减少条件语句。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">算法变动频繁：</strong>
                                <span class="text-gray-600">适合在运行时需要灵活切换算法的场景。</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- State Pattern -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover animate-fadeInUp" style="animation-delay: 0.2s">
                <div class="flex items-center mb-6">
                    <i class="fas fa-sync-alt text-4xl feature-icon mr-4"></i>
                    <h2 class="text-3xl font-bold text-gray-800">状态模式</h2>
                </div>
                
                <p class="text-gray-600 mb-6 leading-relaxed">
                    状态模式允许对象在其内部状态变化时改变其行为。通过将状态相关的行为封装在状态类中，实现对状态转换的控制。
                </p>
                
                <div class="mb-8">
                    <h3 class="text-xl font-semibold mb-4 section-title text-gray-800">
                        <i class="fas fa-star text-sm mr-2"></i>主要特点
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">状态的封装：</strong>
                                <span class="text-gray-600">每种状态对应一个状态类，这些状态类实现相同的状态接口。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">行为的变化：</strong>
                                <span class="text-gray-600">对象的行为与其状态密切相关，状态改变时行为也随之改变。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">简化状态管理：</strong>
                                <span class="text-gray-600">状态转换逻辑可以集中管理，减少了条件判断的复杂性。</span>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 section-title text-gray-800">
                        <i class="fas fa-lightbulb text-sm mr-2"></i>适用场景
                    </h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">行为依赖状态：</strong>
                                <span class="text-gray-600">当对象的行为在不同状态下显著不同，如订单处理状态。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class="text-gray-700">复杂状态管理：</strong>
                                <span class="text-gray-600">当对象的状态转换复杂且频繁时，使用状态模式可以有效管理。</span>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-arrow-right text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <strong class